package 多线程案例;
//Callable——注重结果和过程
//Runnable——注重过程
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo_14 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //重写的方法中有返回值
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int count = 0;
                for (int i = 0; i < 1000; i++) {
                    count++;
                }
                return count;
            }
        };

//        Thread t1 =-new Thread(Callable);//错误

        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        Thread t1 = new Thread(futureTask);
        t1.start();
        System.out.println(futureTask.get());

    }
}
